import java.util.ArrayList;

//两个数组的交集I
class Solution {

    public int[] intersection(int[] nums1, int[] nums2) {
        int[] hash1  = new int[1001];
        int[] hash2  = new int[1001];

        ArrayList<Integer> result = new ArrayList<>();
        for(int i = 0; i < nums1.length || i < nums2.length; i++){
            if(i < nums1.length) hash1[nums1[i]]++;
            if(i < nums2.length) hash2[nums2[i]]++;
        }
        for(int i = 0; i <= 1000; i++){
            if(hash1[i] >= 1 && hash2[i] >= 1){
                result.add(i);
            }
        }
        int[] ret = new int[result.size()];
        int k = 0;
        for (Integer integer : result) {
            ret[k++] = integer;
        }
        return ret;
    }
}